package com.yue.yadmin.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yue.yadmin.model.BaseModel;
import com.yue.yadmin.service.BaseService;
import com.yue.yadmin.utils.Result;

public class BaseController<T extends BaseModel> {
	
	@Autowired
	protected BaseService<T> service;
	
	@RequestMapping("/get")
	@ResponseBody
	public Result getModel(long id){
		T t = service.selectByPrimaryKey(id);
		return Result.ok().put(t);
	}
	
	@RequestMapping("/pageList")
	@ResponseBody
	public Result pageList(T model){
		return Result.page(service.getPage(model));
	}
	
	@RequestMapping("/update")
	@ResponseBody
	public Result update(T model){
		service.update(model);
		return Result.ok();
	}
	
	@RequestMapping("/add")
	@ResponseBody
	public Result add(T model){
		service.insert(model);
		return Result.ok();
	}
	
	@RequestMapping("/delete")
	@ResponseBody
	public Result delete(Long id){
		service.deleteByID(id);
		return Result.ok();
	}
	
}
